/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.satyam.swingvalidator.core;

import java.awt.Container;
import javax.swing.JComponent;

/**
 *
 * @author Satyam
 */
public class ValidationItem {
    private JComponent c;
    private boolean mandatory;
    private boolean validity;
    private ValidationGroup validationGroup;
    
    public ValidationItem(JComponent c,boolean mandatory, ValidationGroup validationGroup){
       this.c = c; 
       this.mandatory = mandatory;
       this.validity = !mandatory;
       this.validationGroup = validationGroup;
    }

    public JComponent getComponent() {
        return c;
    }

    public void setComponent(JComponent c) {
        this.c = c;
    }

    public boolean getMandatory() {
        return mandatory;
    }

    public void setMandatory(boolean isMandatory) {
        this.mandatory = isMandatory;
    }
    
    public boolean getValidity() {
        return validity;
    }
     
    public void setValidity(boolean validity) {
        this.validity = validity;
        validationGroup.updateGroupValidationStatus();
    }

    public ValidationGroup getValidationGroup() {
        return validationGroup;
    }

    public void setValidationGroup(ValidationGroup validationGroup) {
        this.validationGroup = validationGroup;
    }
    
    public boolean isOptionalValidator(){
        return !getMandatory();
    }
    
    public Container getParentContainer(){
        return getValidationGroup().getParent();
    }
    
    public boolean getGroupValidity(){
        return getValidationGroup().getGroupValidity();
    }
    
}
